#ifndef DATABASEMYSQL_H__
#define DATABASEMYSQL_H__

#ifdef WIN32
#	include <winsock2.h>
#endif

#include <mysql.h>
#include "database.h"
#include "database_thread.h"
#include "query_result.h"

namespace engine
{
	struct MySQLDesc
	{
		String database;
		String host;
		uint32 port;
		String user;
		String password;
		uint32 threadCount;
	};

	class DatabaseMySQL : public Database
	{
	public:
		virtual void initialize(const MySQLDesc& desc);
		virtual void finalize();
	};

	class DatabaseThreadMySQL : public DatabaseThread
	{
	public:
		virtual void* entry();

		virtual QueryResultSet* query(const String& sql);
		virtual bool execute(const String& sql);

		MYSQL* mMysql;
	};

	class QueryResultMySQL : public QueryResult
	{
	public:
		QueryResultMySQL(MYSQL_RES *result, uint32 rowCount, uint32 fieldCount);

		~QueryResultMySQL();

		bool nextRow();

	private:
		enum DataField::DataTypes convertNativeType(enum_field_types mysqlType) const;
		void endQuery();

		MYSQL_RES *mResult;
	};

}

#endif
